package cn.controlsys.common.mq;


import cn.controlsys.common.mq.builder.RabbitMQAccessBuilder;
import cn.controlsys.common.mq.interfaces.MessageSender;
import cn.controlsys.common.mq.object.DetailResponse;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Description: Created by Administrator on 2018/4/19.
 */
@Component
public class RabbitMQProducer {
    @Autowired
    ConnectionFactory connectionFactory;


    private MessageSender sendMonthlyOperationNoAck;

    private MessageSender messageMonthlyBillSenderNoAck;

    private MessageSender sendMeterNumMessageNoAck;

    @PostConstruct
    public void init() throws IOException, TimeoutException {
        RabbitMQAccessBuilder mqAccessBuilder = new RabbitMQAccessBuilder(connectionFactory);

        mqAccessBuilder.buildTopicMessageSenderNoAck(MQConstants.TOPIC_EXCHANGE,
                MQConstants.SAIHEYI_OPERATION_KEY, MQConstants.SAIHEYI_OPERATION_QUEUE);



    }

    /**
     * Description: 发送不需要手动去确认的消息 -- 月账单(解绑)
     * @param byteObject 序列化后的字节对象
     * @author: shanzheng
     * @date: 11:49 2018/5/9
     * @return: cn.controlsys.job.common.mq.object.DetailResponse
     */
    public DetailResponse sendMonthlyOperationNoAck(byte[] byteObject) {
        return sendMonthlyOperationNoAck.send(byteObject);
    }

//    /**
//     * Description: 发送不需要手动去确认的消息 -- 月账单
//     * @param byteObject 序列化后的字节对象
//     * @author: shanzheng
//     * @date: 11:49 2018/5/9
//     * @return: cn.controlsys.job.common.mq.object.DetailResponse
//     */
//    public DetailResponse sendMonthlyBillNoAck(byte[] byteObject) {
//        return messageMonthlyBillSenderNoAck.send(byteObject);
//    }
//
//    /**
//     * Description: 发送不需要手动去确认的消息 -- 统计设备数量
//     * @param object 对象
//     * @author: shanzheng
//     * @date: 11:49 2018/5/9
//     * @return: cn.controlsys.job.common.mq.object.DetailResponse
//     */
//    public void sendMeterNumMessageNoAck(Object object) {
//        RabbitTemplate rabbitTemplate = sendMeterNumMessageNoAck.getTemplate();
//        rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//        rabbitTemplate.convertAndSend(object);
//        //return sendMeterNumMessageNoAck.send(object);
//    }
}
